#ifndef TEXTURE_H
#define TEXTURE_H

#include "TextureLoader.h"
#include <string>

class Texture
{
	unsigned int m_Texture;
	std::string m_filename;
	bool m_Loaded;
	bool m_mirror;

public:
	Texture( const std::string& filename )
	{
		m_filename = filename;
		m_Loaded = false;
		m_mirror = false;
	}

	Texture()
	{
		m_Loaded = false;
		m_mirror = false;
	}

	void setMirror( bool c )
	{
		m_mirror = c;
	}

	bool getMirror()
	{
		return m_mirror;
	}

	void setFilename(const std::string& filename )
	{
		m_filename = filename;
	}

	bool isValid()
	{
		return m_filename.length() > 0;
	}

	void bind()
	{
		if(!m_Loaded)
		{
			m_Texture = TextureLoader::getInstance().loadTexture( m_filename );
			m_Loaded = true;
		}
		
		// Went wrong?
		if( m_Texture == 0 )
		{
			printf("Cannot use texture %s\n", m_filename.c_str() );
			return;
		}

		// Enable alpha-blending
		glEnable(GL_ALPHA_TEST);
		glAlphaFunc(GL_GREATER, 0.99f); 
		
		// Reset color..
		glColor3f(1, 1, 1);

		// Bind!
		glEnable( GL_TEXTURE_2D );
		glBindTexture(GL_TEXTURE_2D, m_Texture);
	}

	void unbind()
	{
		glDisable(GL_ALPHA_TEST);
		glDisable( GL_TEXTURE_2D );
	}
};

#endif